<?php


namespace Tbf\Bundle\AlipayBundle\Command;


use Guzzle\Http\Url;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;
use Tbf\Bundle\AlipayBundle\Model\AlipaySign;
use Tbf\Bundle\TbfBundle\Command\TbfCommand;

class TestCommand extends TbfCommand{
    protected function configure()
    {
        $this
            ->setName('tbf:alipay:test')
            ->setDescription('test alipay')
            ->addOption('force');
    }
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $ret = $input->getOption('force');
        if ($ret===false){
            throw new \Exception('you need force to run this command');
        }
$data = Yaml::parse(<<<'YML'
xxx
YML
);
        $output_data = array();
        foreach($data as $entity){
            $output_data[$entity['name']] = urldecode($entity['value']);
        }
        $output_data = AlipaySign::md5SignArray($output_data,$this->getContainer()->getParameter('tbf_alipay.app_secret'));
        $url = Url::factory('http://fruit.sxz.dashi.us/alipay_callback/create_direct_by_user_page');
        $url->setQuery($output_data);
        $output->writeln( (string)$url);
    }
}